import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../components/layout/Layout.vue'

// 符合路由嵌套即可
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/user/Login.vue')
    },
    {
      path: '/',
      redirect: '/admin'
    },
    {
      path: '/admin',
      name: 'layout',
      component: Layout,
      redirect: '/admin/home',
      children: [
        {
          path: 'home',
          component: () => import('../views/home/Home.vue')
        },
        {
          path: 'goods',
          redirect: '/admin/goods/classify',
          children: [
            {
              path: 'classify',
              component: () => import('../views/goods/GoodsClassify.vue')
            },
            {
              path: 'manage',
              component: () => import('../views/goods/GoodsManage.vue')
            }
          ]
        },
        {
          path: 'order',
          redirect: '/admin/order/manage',
          children: [
            {
              path: 'manage',
              component: () => import('../views/order/OrderManage.vue')
            },
            {
              path: 'tui',
              component: () => import('../views/order/OrderTui.vue')
            }
          ]
        },


        {
          path: 'empty',
          component: () => import('../views/other/Empty.vue')
        },

        // 内层路由嵌套404页面
        {
          path: '/:pathMatch(.*)*',
          component: () => import('../views/other/Error404.vue')
        },

      ]
    },


    // 404页面
    {
      path: '/:pathMatch(.*)*',
      component: () => import('../views/other/Error404.vue')
    },
  ]
})

export default router
